import numpy as np

# 构建多维数组

nd_arr = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])

print(nd_arr)
print(type(nd_arr))

a = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])

print(a[::-1])
print(a[1:5])
print(a[1])

print("=" * 10)
print(nd_arr)
print(nd_arr[1, 2])  # 第一个代表行方向的切片和索引，第二个代表列方向的切片和索引

# 切片
print(nd_arr[::, 1:3])

# 赋值
nd_arr[::, 1:3] = 10

print(nd_arr)

# 形状
print(nd_arr.shape)
print(nd_arr)

print(nd_arr[(0, 1), (0, 1)])

# bool切片
print(nd_arr[::, [True, False, False, True]])

print("=" * 10)
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

print(arr + 1)
print(arr - 1)
print(arr / 2)
print(arr // 2)
print(arr * 2)
print(arr % 2)

print(arr > 5)

#  bool值索引，取出所有大于5的数
print(arr[arr > 5])

arr1 = np.array([[1, 2, 3], [4, 5, 6]])
arr2 = np.array([[1, 2, 3], [4, 5, 6]])

# 对位运算
print(arr1 + arr2)
print(arr1 - arr2)
print(arr1 * arr2)
print(arr1 / arr2)

arr3 = arr2.reshape((3, 2))

print("=" * 10)
print(arr1)
print(arr3)

# 矩阵相乘
print(arr1.dot(arr3))

arr = np.array([1, 2, 3, 4, 5, 6])

# 自然对数
print(np.log(arr))

print(arr1.T)
